package com.lishe.lishe.lishe.module.mall.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lishe.lishe.Imageloader.FlexibleRoundeBitmapDisplayer;
import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerviewBaseAdapter;
import com.lishe.lishe.lishe.module.mall.bean.MallGoods;
import com.lishe.lishe.lishe.module.mall.presenter.MallMainAdapterPresenter;
import com.lishe.lishe.lishe.utils.Utils;

import java.util.List;

/**
 * Created by shino on 2017/11/6.
 * 商城首页猜你喜欢
 */

public class MallMaybeLikeAdapter extends RecyclerviewBaseAdapter {
    List<MallGoods> mallGoods;
    Context context;
    ImageLoaderUtils imageLoaderUtils;

    public MallMaybeLikeAdapter(Context context, List<MallGoods> mallGoods) {
        imageLoaderUtils = new ImageLoaderUtils(Utils.dip2px(context,5), FlexibleRoundeBitmapDisplayer.CORNER_TOP_LEFT_RIGHT);
        this.mallGoods = mallGoods;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolderMy(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_classification_mall, parent, false);
        ItemViewHolder holder = new ItemViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolderMy(RecyclerView.ViewHolder holder, int position) {
        final MallGoods mallGoodsObject = mallGoods.get(position);
        imageLoaderUtils.displayImage(mallGoodsObject.getImage_default_id(), ((ItemViewHolder) holder).goods_img);
        ((ItemViewHolder) holder).goods_name.setText(mallGoodsObject.getTitle());
        ((ItemViewHolder) holder).integral.setText((int) (mallGoodsObject.getPrice() * 100) + "");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MallMainAdapterPresenter.maybeLoveItemOnClick((Activity)context, mallGoodsObject);
            }
        });
    }

    @Override
    public int getItemCountMy() {
        return mallGoods == null ? 0 : mallGoods.size();
    }

    @Override
    public int getItemViewTypeMy(int position) {
        return 0;
    }


    class ItemViewHolder extends RecyclerView.ViewHolder {
        //item
        private ImageView goods_img;
        private TextView goods_name;
        private TextView integral;

        public ItemViewHolder(View v) {
            super(v);
            goods_img = v.findViewById(R.id.goods_img);
            goods_name = v.findViewById(R.id.goods_name);
            integral = v.findViewById(R.id.integral);
        }
    }
}
